{% extends front.html %}

{% block title %}
{% if query.get("q") %}{{ options.site_name }} - {{ query.get("q") }} - 迅雷离线下载分享
{% elif query.get("t") %}{{ options.site_name }} - {{ query.get("t") }} - 迅雷离线下载分享
{% elif query.get("creator") %}{{ options.site_name }} - {{ email2name(query.get("creator")) }} - 迅雷离线下载分享
{% else %}{{ options.site_name }} - 迅雷离线下载分享{% end %}
{% end %}

{% block more_head %}
<link rel="alternate" type="application/atom+xml" href="?feed=rss" />
{% end %}

{% block info %}
{% if options.using_xss or handler.installed_userjs() %}
{% raw modules.TagList() %}
{% else %}
{% include info.html %}
{% end %}
{% include author_info.html %}
{% end %}

{% block list %}
<ul class="task-list">
  <li class="push-top"></li>
  {% raw modules.TaskItems(tasks) %}
  <li class="push-bottom"></li>
</ul>
{% end %}

{% block foot %}
<script>
  function _gc(name) {
    return document.getElementsByClassName(name);
  }
  function resize_item(tname) {
    if (tname.offsetWidth-200 < tname.firstChild.offsetWidth) {
      tname.lastChild.setAttribute("style", "right: 0;");
    } else {
      tname.lastChild.removeAttribute("style");
    }
  }
  var OnResize = function() {
    var tnames = _gc("tname");
    for(var i=0; i<tnames.length; i++) {
      resize_item(tnames[i]);
    }
  }
  window.onresize = OnResize;
  window.onload = OnResize;

  //load next page
  var next_page_sent = false;
  $(document).bind("scroll", function() {
    if ($(window).height() + $(document).scrollTop() + 1000 > $(document).height() && !next_page_sent) {
      // load next page
      next_page_sent = true;
      $.get("/next", {
          s: $(".task-item:last").attr("data-task-id"),
          q: {% raw json_encode(query.get('q', '')) %},
          t: {% raw json_encode(query.get('t', '')) %},
          a: {% raw json_encode(query.get('a', '')) %},
         },
            function(content) {
              if ($.trim(content) == "") {
                $(".task-list").unbind("scroll");
              } else {
                var content = $(content);
                $(".task-list .push-bottom").before(content);
                $.each(content.find(".tname"), function(i, n) {
                  resize_item(n);
                });
                next_page_sent = false;
              }
            });
    }
  });

  // fancybox
  $(".get-lixian-url").fancybox({ width: 700 });
  $(".edit-button").fancybox({ width: 700 , height: 250});

  </script>
{% end %}
